<?php

namespace app\common\model\mysql;

use think\Model;

class SGoodsGroupUser extends Model
{
    public function getGroupUserList($where,$field = '*'){
        $order = [
            "a.create_time" =>"desc",
        ];
        $result = $this->alias('a')->join('s_order b', 'a.order_id = b.order_id')->where($where)->order($order)->field($field)->select();
        return $result->toArray();
    }

    public function getGroupUserStatus($orderId,$field = '*'){
        $where = [
            ['order_id','=',$orderId],
        ];
        $result = $this->alias('a')->join('s_goods_group_buying b', 'a.group_buying_id = b.group_buying_id')->where($where)->field($field)->find();
        return $result->toArray();
    }

    /**
     * 查询拼团用户数据
     * @param $where
     * @param string $field
     * @param int $limit
     * @return mixed
     */
    public function getGroupUserLimitList($where, string $field = '*', int $limit = 3){
        $order = [
            "create_time" =>"desc",
        ];
        $result = $this->distinct(true)->where($where)->order($order)->limit($limit)->field($field)->select();
        return $result->toArray();
    }
}
